package client;

import server.core.AbstractSend2Data;
import server.core.AbstractSenderFactory;
import server.core.factory.CoapSenderFactory;
import server.core.factory.SimpleFactory;
import server.core.factory.TcpSenderFactory;

/**
 * describe:所有类型的设备下发流程.
 * 1.到 redis 查找设备信息
 * 2.调用 sendData() 接口，
 * 3.响应调用者
 *
 * @author helloworldyu
 * @data 2018/1/22
 */
public class SendDataService {
	private AbstractSenderFactory factory;

	public SendDataService(AbstractSenderFactory factory) {
		this.factory = factory;
	}


	public void service(String condition ){
		//===========创建发送者============
		AbstractSend2Data sender = factory.createSender(condition);
		//=====调用发送者的 sendData()=====
		String result = sender.sendData();
		//==========响应调用者=============
		System.out.println("响应调用者  "+result);
	}


//工厂方法模式测试
//	public static void main(String[] args) {
////		AbstractSenderFactory factory = new TcpSenderFactory();
//		AbstractSenderFactory factory = new CoapSenderFactory();
//
//		SendDataService sendDataService = new SendDataService(factory);
//		sendDataService.service("hgs");
//	}


	//简单工厂 + 工厂方法模式测试
	public static void main(String[] args) {
		AbstractSend2Data sender = SimpleFactory.createSender("TCP", "HGS");

		if( null != sender ){
			String s = sender.sendData();
			System.out.println("下发数据结果: "+ s);
		}else {
			System.out.println("找不到");
		}

	}

}